package entities;


import java.io.Serializable;
import java.lang.String;
import java.util.List;

import javax.persistence.*;

import org.apache.commons.codec.digest.DigestUtils;

import dto.UserDTO;





/**
 * Entity implementation class for Entity: UserEntity
 *
 */
@Entity
@Table(name="USERS")
public class UserEntity implements Serializable {
	private static final long serialVersionUID = 1L;
	   
	@Id
	private String username;
	private String password;
	private String firstname;
	private String lastname;
	private String email;
	
	@ElementCollection(targetClass = GroupEnum.class)
    @CollectionTable(name = "USER_GROUP",
                    joinColumns = @JoinColumn(name = "username"))
    @Enumerated(EnumType.STRING)
    @Column(name="groupname")
	private List<GroupEnum> groups;
	
	
	public UserEntity() {
		super();
	}   
	
	public UserEntity(UserDTO user){
		this.username=user.getUsername();
		this.password=DigestUtils.sha512Hex(user.getPassword());
		this.firstname=user.getFirstName();
		this.lastname=user.getLastName();
		this.email=user.getEmail();
	}
	
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}   
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}   
	public String getFirstname() {
		return this.firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}   
	public String getLastname() {
		return this.lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}   
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
   
	public List<GroupEnum> getGroup() {
		return groups;
	}
	public void setGroup(List<GroupEnum> group) {
		this.groups = group;
	}

	
}
